﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace FineUI.Examples
{
    public partial class admin_readdcourse : System.Web.UI.Page
    {

        protected void SetNewInfom()
        {

            tbxCourseId.Text = Session["C_Id"].ToString();
            tbxCourseName.Text = Session["C_Name"].ToString();
            tbxCourseCredit.Text = Session["C_Credit"].ToString();
           
        }
        protected void Page_Load(object sender, EventArgs e)
        {


            if (Session["UserName"] == null)
            {
                Response.Redirect("~/login.aspx");
            }

            if (!IsPostBack)
            {
                SetNewInfom();
                Alert.Show("请输入新的课程信息", MessageBoxIcon.Information);
            }
           
            /*
            Session["C_Id"] = CurrentC_Id;
            Session["C_Name"] = CurrentC_Name;
            Session["C_Credit"] = CurrentC_Credit;
             */

        }


        protected void btnAddCourse_Click(object sender, EventArgs e)
        {
            if (tbxCourseCredit.Text == "" || tbxCourseId.Text == "" || tbxCourseName.Text == "")
            {
                Alert.ShowInTop("请输入完整的信息!");
                return;
            }



            string currentId = tbxCourseId.Text.ToString();
            string currentName = tbxCourseName.Text.ToString();
            string  currentCredit = tbxCourseCredit.Text.ToString();


            Maticsoft.BLL.Course Course = new Maticsoft.BLL.Course();
            Maticsoft.Model.Course CourseInfom = new Maticsoft.Model.Course();

            CourseInfom.C_Id = currentId;
            CourseInfom.C_Credit = currentCredit;
            CourseInfom.C_Name = currentName;


            if (Course.Exists(currentId))
            {
                Alert.ShowInTop("该课程编号已存在");
                return;

            }

         
            if (Course.Add(CourseInfom))
            {
                Response.Redirect("~/admin_updatecourse.aspx");

            }
            else
            {
                Alert.ShowInTop("课程修改失败");
            }




        }
    }
}